package com.zmj.sy.mom.srv.aps.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: lyh
 * @Date: 2024-09-26-16:04
 * @Description:
 */
public class TimeTransferUtils {
    /**
     * @Description:  String转LocalDateTime：yyyy-MM-dd HH:mm:ss
     * @author: lyh
     * @Param:
     * @date: 2024/9/26 16:03
     */
    public static LocalDateTime strToLocalDateTime(String time){
        // 创建 DateTimeFormatter 对象
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 使用 formatter 解析字符串
        LocalDateTime   localDateTime = LocalDateTime.parse(time, formatter);
        // 输出结果
        System.out.println("Parsed LocalDateTime: " + localDateTime);
        return  localDateTime;
    }


    /**
     * @Description:  LocalDateTime转String：yyyy-MM-dd HH:mm:ss
     * @author: lyh
     * @Param:
     * @date: 2024/9/26 16:05
     */
    public static String localDateTimeToStr(LocalDateTime localDateTime){
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 将 LocalDateTime 转换为 String
        String  timeStr = localDateTime.format(formatter);
        // 输出结果
        System.out.println("Formatted LocalDateTime: " + timeStr);
        return timeStr;
    }
}
